
package com.banach.prema.web;

import com.banach.prema.dto.cmd.SosCmd;
import com.banach.prema.dto.query.SosPageQuery;
import com.banach.prema.dto.vo.SosVO;
import com.banach.prema.service.SosService;
import com.ego.base.dto.vo.AddressVO;
import com.ego.framework.annotation.Module;
import com.ego.framework.annotation.ReqParam;
import com.ego.framework.annotation.RestApi;
import com.ego.framework.dto.Response;
import com.ego.framework.model.CustomizePage;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author ajun
 *
 */
@RestController
@RequestMapping(value = "/sos")
@Module("求救")
public class SosController {

	@Resource
	private SosService sosService;

	@RestApi(name = "发送求救",idx = 1)
	@PostMapping(value="/send")
	public Response send(@RequestBody SosCmd sosCmd) {
		return sosService.send(sosCmd);
	}

	@RestApi(name = "结束求救",idx = 1)
	@PostMapping(value="/end/{sosId}")
	public Response end(@PathVariable("sosId")@ReqParam(label = "求救ID",required = true) Long sosId) {
		return sosService.end(sosId);
	}

	@RestApi(name = "求救分页查询",idx = 2)
	@GetMapping(value="/page")
	public Response<CustomizePage<SosVO>> selectPage(SosPageQuery pageQuery) {
		return sosService.selectPage(pageQuery);
	}

	@RestApi(name = "我的求救分页查询",idx = 3)
	@GetMapping(value="/min/page")
	public Response<CustomizePage<SosVO>> selectMyPage(){
		return sosService.selectMyPage();
	}

	/**
	 * 求救信息页面
	 * @param request
	 * @return
	 */
	@RestApi(name = "求救信息页面",idx = 10)
	@GetMapping(value="/view/{sosId}")
	public ModelAndView getViewById(HttpServletRequest request, @PathVariable("sosId")@ReqParam(label = "求救ID",required = true) Long sosId) {
		return sosService.getViewById(request,sosId);
	}

	@RestApi(name = "获取求救当前位置",idx = 11)
	@GetMapping(value="/current-location/{sosId}")
	public Response<AddressVO> getCurrentLocation(@PathVariable("sosId")@ReqParam(label = "求救ID",required = true) Long sosId) {
		return sosService.getCurrentLocation(sosId);
	}

}
